# 恢复并修复video_processor.py文件
import os

# 文件路径
original_file = r'd:\未知\yolo_apply\video_processing\video_processor.py'
backup_file = r'd:\未知\yolo_apply\video_processing\video_processor.py.backup'

# 读取完整的备份文件内容
with open(backup_file, 'r', encoding='utf-8') as f:
    lines = f.readlines()

# 修复第1849行的语法错误
if len(lines) >= 1849:
    # 查找错误区域（包含注释行）
    for i in range(1845, 1855):
        if i < len(lines) and '# 错误率过高时触发警告和恢复' in lines[i]:
            # 替换接下来的几行代码，确保使用正确的变量名
            if i+1 < len(lines):
                lines[i+1] = '                current_time_value = time.time()\n'
            # 更新相关引用
            if i+2 < len(lines):
                lines[i+2] = lines[i+2].replace('now', 'current_time_value').replace('current_time_temp', 'current_time_value')
            # 更新last_error_time赋值
            if i+6 < len(lines):
                lines[i+6] = lines[i+6].replace('now', 'current_time_value').replace('current_time_temp', 'current_time_value')
            break

# 写入修复后的完整内容
with open(original_file, 'w', encoding='utf-8') as f:
    f.writelines(lines)

print(f"已成功从备份恢复并修复了 {original_file} 文件")